Simple Report and Document Generation, Utilising LBBROWSE.DLL

by Mike Bradbury

Home

Wire 1.0

Gif Viewer

Report Generation

Flow Charting

Stylebits Corner

Tip Corner

API Corner

CodeAChrome

Sprite Byte

Control Panel Applets

HTTPS Data

Eddie

Submissions

Index


Alyce Watson, to whom we remain eternally indebted, gave us a fine tool to embed a browser control in our LibertyBASIC applications. The dll opens up many possibilities for the use of html, java, javascript, etc to enhance the appearance and functionality of those applications. Browsers and html need not apply just to internet applications, they can be used to simplify what may be complex operations, with the hard work done in the background by the Windows API. Compare the relative simplicity of this demo code with what would be required to attempt to produce the same results, including color printing, using native LB code.

I understand that some LB users will have little or no knowledge of html, but I hope that the demo code included within the newsletter, will be simple enough to follow and perhaps adapt for use within their own applications. It may thus encourage further study of html, which in my opinion is easier than LibertyBASIC. I have included a few html tags and parameters which stand out as values the programmer can easily change, to produce personal choice results, without having to know much about html. Standard browser colors can easily be found from a Google Search; there are I think 140 to choose from, as can simple on-line html tutorials

The demo produces a data report, with colored text, from dummy data stored in a string and the output is formatted into a table. The table borders can be removed or shown at will, as can the background. A report heading can be entered into a textbox and is displayed at the top of the form. The table can be sorted on either of the two columns.

The report is fully printable via the "BrowserPrint" function of the dll, with all the standard browser print options. Everything is printed as seen in the browser control, table borders if shown, text colors and graphic objects.

The background can also be printed if the option is set in iexplorer Internet Options. Alyce has even included functions to access iexplorer settings and print preview, among many others. Studying the readme file included with the dll, will reveal all.

Examination of the extract from the demo code, showing the section which handles generation of the html code, indicates that fixed parameters have been used for colors, column widths and titles, etc but these could easily be changed to variables which could be set by the user from textboxes, listboxes, menu options or whatever is the programmers favourite method. For example, the first column title has been set to "Row #" but could be replaced with a variable such as column1Title$ which the user entered into a textbox.

The line indicated by '************ would then be replaced with:

"<tr><td width=10% align=center><font size=4 color=green>"+column1Title$+"</font></td>"

The code specification for HTML states that colors, font sizes, table widths etc should be enclosed in quotes, eg <font size="4"> or <table width="50%"> but I find that IE6 accepts these parameters without the quotes, which avoids the need for careful insertion of chr$(34) in the LB code. Similarly, the alternative text label (alt="some text") functions without the quotes provided there are no spaces, hence in the demo, I used an underscore to conjoin the text (alt=logo_here). Earlier versions of the browser may require you to provide the quotes. As I only have access to IE6, I am unable to verify the requirements of other versions, just be aware of a possible need for the quotes.

As an example, the line indicated by '************ would be replaced with:

"<tr><td width="+chr$(34)+"10%"+chr$(34)+" align="+chr$(34)+"center"+chr$(34)+"><font size="+chr$(34)+_

"4" +chr$(34)+"color="+chr$(34)+"green"+chr$(34)+">Row #</font></td>"

'Code extract
'open file to store report
open reportFileName$ for output as #htm
'generate html code for report page formatted as table, three columns per row
'note fixed background graphic over which table scrolls.
#htm, "<html><head><title>LibertyBASIC/HTML report generator</title></head>";_
      "<body background=";backGroundFile$;" bgproperties=fixed><HR size=6 color=gold>";_
      "<font size=5 color=red><I>";reportTitle$;"</I>";_
      "<img src=";logoImgFile$;" hspace=10 alt=logo_here>";date$();"</font> (Sorted by: ";_
       columnTitle$(sortColumn);")</font><BR><HR color=red><BR>"
#htm, "<table border=";tableBorder;" width=100% cellspacing=0 bordercolor=gainsboro>"
'enter column titles
#htm, "<tr><td width=20% align=left><font size=4 color=green>";columnTitle$(1);"</font></td>"
#htm, "<<td width=50% align=left><font size=4 color=green>";columnTitle$(2);"</font></td>"
#htm, "<td width=30% align=left><font size=4 color=green> </font></td></tr>"
      fontColor$="blue" 'font color for first ten items
      'enter data from arrays into rows of a table
      for row=1 to 20
          #htm, "<tr><td width=20%><font size=2 color=";fontColor$;">"+myData$(row,1);" </font></td>"
          #htm, "<td width=50%><font size=2 color=";fontColor$;">"+myData$(row,2);" </font></td>"
          #htm, "<td width=30%><font size=2 color=";fontColor$;"> </font></td></tr>"
          if row=10 then fontColor$="purple" 'font color for next ten items
      next row
#htm, "</table><BR><BR>This HTML generated report is produced in an embedded browser "+_
      "using lbbrowse.dll, generously gifted to us by Alyce, to whom we are "+_
      "eternally indebted! This dll gives us a tool to display and print data "+_
      "and documents in tables, frames, full colour, including graphics etc.</body></html>"
close #htm
'End of Code extract

The full demo can be found in the newsletter archive which you must download and is named htmlReports.bas

Also just to remind you, you need to visit Alyces website ( alycesrestaurant.com/) and download lbbrowse.dll and don't forget to include the usual credits if you use the dll in any applications you may distribute. The demo needs the dll to be in the same folder as all the other files.

I would also like to take the opportunity to thank Alyce, both on my behalf and also that of the wider LB community, for her generosity in making lbbrowse and many other dlls, freely available. Her enhancements to LibertyBASIC are of incalculable value.

THANK YOU Alyce.

We must also not forget Carl and his crew, without whom LB would not exist!

Enjoy. Mike.